package com.bs.resa.service.impl;

import com.bs.resa.common.DatetimeUtils;
import com.bs.resa.dao.FileMapper;
import com.bs.resa.dao.LogMapper;
import com.bs.resa.service.LogService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * @Author lin
 * @date 2019/4/2 18:43
 */
@Service
public class LogServiceImpl implements LogService {
    @Value("${fastdfs_setting.IMAGE_SERVER_URL}")
    private String url;
    @Resource
    LogMapper logMapper;
    @Resource
    FileMapper fileMapper;
    /**
     * 获得日志
     *
     * @param pid
     * @return
     */
    @Override
    public List<Map<String, Object>> queryLogByPid(String pid) {
        List<Map<String, Object>> logs=logMapper.getByPid(pid);
        for(Map<String,Object> map:logs){
            if(map.get("fileId")==null){
               map.put("files",null);
            }else{
                map.put("files",fileMapper.querybyId((Long) map.get("fileId")));
            }

            map.put("getLow",DatetimeUtils.getLnow(((Date)map.get("datas")).getTime()));
            map.put("url",url);
        }
        return logs;
    }


}
